/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:lenovo
 * Date:2024-06-02
 * Time:22:52
 */
import java.util.Arrays;
import java.util.Scanner;

public class MergeArray {
    public static void mergeAndSort(int[] A, int m, int[] B, int n) {
        // 将数组 B 的元素追加到数组 A 的末尾
        for (int i = 0; i < n; i++) {
            A[m + i] = B[i];
        }

        // 对合并后的数组进行排序
        Arrays.sort(A);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);


        int[] A = new int[100];
        System.out.println("请输入数组 A 的元素：");
        for (int i = 0; i < A.length; i++) {
            A[i] = scanner.nextInt();
        }

        int[] B = new int[100];
        System.out.println("请输入数组 B 的元素：");
        for (int i = 0; i < B.length; i++) {
            B[i] = scanner.nextInt();
        }

        mergeAndSort(A, A.length, B, B.length);

        // 输出合并后的有序数组 A
        System.out.println("合并后的有序数组 A：");
        for (int num : A) {
            System.out.print(num + " ");
        }
    }
}
